
package com.dave.gd.common.util.xml.model;

import java.io.Serializable;

import org.dom4j.Element;

import com.dave.gd.common.util.xml.XmlBeanUtil;



/**
 * javaBean结构体基类
 * 
 * 
 * 
 */
public abstract class XmlBean implements Serializable {
	private static final long serialVersionUID = -6117454645160921516L;

	/**
	 * 序列化
	 * 
	 * @return Element
	 */
	public Element serialize() {
		return XmlBeanUtil.serialize(this);
	}

	/**
	 * 序列化
	 * 
	 * @return Element
	 */
	public Element serialize(String localName) {
		return XmlBeanUtil.serialize(this, localName);
	}

	/**
	 * 反序列化
	 * 
	 * @param localEle
	 *            Element
	 */
	public void unserialize(Element localEle) {
		XmlBeanUtil.unserialize(this, localEle);
	}

	/**
	 * 输出XML
	 * 
	 * @param encoding
	 *            编码
	 * @return xml报文
	 */
	public String asXml(String encoding) {
		return XmlBeanUtil.ele2Xml(serialize(), encoding);
	}

	/**
	 * 反序列化
	 * 
	 * @param xml
	 *            xml报文
	 */
	public void asBean(String xml) {
		Element rootCopyEle = XmlBeanUtil.xml2Ele(xml);
		XmlBeanUtil.unserialize(this, rootCopyEle);
	}

	/**
	 * 输出XML
	 * 
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return serialize().asXML();
	}

}
